﻿using System.Collections.Generic;
using Utility.Global;
using Utility.Persistence_Service;

namespace Application_Core.Kunde_Component.Data_Access_Layer
{
    public class Kunde : Entity, ConvertableToDTO<KundeDTO>
    {
        public virtual int Id { get; protected set; }

        public virtual int Nummer { get; set; }

        public virtual string Nachname { get; set; }

        public virtual string Vorname { get; set; }

        public virtual Adresse Adresse { get; set; }

        public Kunde() { }

        public Kunde(int nummer, string nachname, string vorname, Adresse adresse)
        {
            this.Nummer = nummer;
            this.Nachname = nachname;
            this.Vorname = vorname;
            this.Adresse = adresse;
        }

        public virtual KundeDTO ToDTO()
        {
            KundeDTO kunde = new KundeDTO();
            kunde.Nummer = this.Nummer;
            kunde.Nachname = this.Nachname;
            kunde.Vorname = this.Vorname;
            kunde.Adresse = this.Adresse.ToDTO();
            return kunde;
        }

        public override bool Equals(System.Object obj)
        {
            if (obj == null)
            {
                return false;
            }

            if (GetType() != obj.GetType())
            {
                return false;
            }

            Kunde kunde = (Kunde)obj;

            return (Id.Equals(kunde.Id)) && (Nummer.Equals(kunde.Nummer)) &&
                (Vorname.Equals(kunde.Vorname)) && (Nachname.Equals(kunde.Nachname)) &&
                (Adresse.Equals(kunde.Adresse));
        }

        public override int GetHashCode()
        {
            int prime = 31;
            int result = 1;
            result = prime * result + Id.GetHashCode();
            result = prime * result + Nummer.GetHashCode();
            result = prime * result + Vorname.GetHashCode();
            result = prime * result + Nachname.GetHashCode();
            result = prime * result + Adresse.GetHashCode();
            return result;
        }
    }
}
